import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static int n;
    public static int[] minArr;
    public static int[] arr;
    public static int count;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t > 0) {
            t--;
            n = sc.nextInt();
            minArr = new int[n];
            count = 0;
            boolean flag = false;
            for (int i = 0; i < n; i++) {
                minArr[i] = sc.nextInt();
                if (minArr[i] > n) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                System.out.println(0);
            } else {
                arr = new int[n];
                arr[0] = minArr[0];
                Map<Integer, Boolean> map = new HashMap<>();
                for (int i = 0; i < n; i++) {
                    map.put(i + 1, false);
                }
                map.put(arr[0], true);
                dfs(1, arr[0], map);
                System.out.println(count);
            }
        }

        sc.close();
    }

    public static void dfs(int index, int preMin, Map<Integer, Boolean> map) {
        if (index == n) {
            count++;
            return;
        }

        if (minArr[index] < preMin) {
            arr[index] = minArr[index];
            map.put(index, true);
            dfs(index + 1, minArr[index], map);
        } else {
            for (int i = preMin + 1; i <= n; i++) {
                if (!map.get(i)) {
                    arr[index] = i;
                    map.put(i, true);
                    dfs(index + 1, minArr[index], map);

                    //回溯
                    arr[index] = 0;
                    map.put(i, false);
                }
            }
        }
    }
}
